mod pendulum;

use ggez::{Context, GameResult, GameError, graphics, glam::Vec2};

pub struct State{
    pendulum1: pendulum::Pendulum,
    pendulum2: pendulum::Pendulum,
    pendulum3: pendulum::Pendulum,
}

impl State{
    pub fn new() -> State {


        let origin = Vec2{x: 400.0,y: 0.0};
        let r = 200.0;
        let pendulum1 = pendulum::Pendulum::new(origin, r);

        let origin = pendulum1.get_g_location();
        let r = 150.0;
        let pendulum2 = pendulum::Pendulum::new(origin, r);

        let origin = pendulum2.get_g_location();
        let r = 100.0;
        let pendulum3 = pendulum::Pendulum::new(origin, r);

        State { pendulum1, pendulum2, pendulum3 }
    }
}

impl ggez::event::EventHandler<GameError> for State {
    fn update(&mut self, _ctx: &mut Context) -> GameResult {
        self.pendulum1.update();
        self.pendulum2.set_origin(self.pendulum1.get_g_location());
        self.pendulum2.update();
        self.pendulum3.set_origin(self.pendulum2.get_g_location());
        self.pendulum3.update();
        Ok(())
    }
    fn draw(&mut self, ctx: &mut Context) -> GameResult {
        let mut canvas = graphics::Canvas::from_frame(ctx, graphics::Color::WHITE);
        self.pendulum1.display(ctx, &mut canvas);
        self.pendulum2.display(ctx, &mut canvas);
        self.pendulum3.display(ctx, &mut canvas);
        canvas.finish(ctx)?;
        Ok(())
    }
}